package com.ctshk.sapp.guide.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.guide.dto.GroupDistributionListDTO;
import com.ctshk.rpc.guide.dto.GroupInfoDTO;
import com.ctshk.rpc.guide.dto.GuideCollarQueryLeisureDTO;
import com.ctshk.rpc.guide.req.*;
import com.ctshk.rpc.guide.service.IGroupDistributionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 团队分配表（派团） 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-02-25
 */
@Api(value = "派团管理", tags = "派团管理")
@RestController
@RequestMapping("/group/distribution")
public class GroupDistributionController extends BaseController {
    @DubboReference
    private IGroupDistributionService groupDistributionService;

    @ApiOperation(value = "空闲的领队or导游", notes = "空闲的领队or导游")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.QUERY, operTitle = "空闲的领队", operDesc = "空闲的领队")
    @PostMapping("/getGuideCollarLeisure")
    public Result<List<GuideCollarQueryLeisureDTO>> list(@RequestBody @Valid GuideCollarQueryLeisureReq req) {
        return groupDistributionService.select(req);
    }

    @ApiOperation(value = "团队分配表（派团）列表", notes = "团队分配表（派团）列表")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.QUERY, operTitle = "团队分配表（派团）列表", operDesc = "团队分配表（派团）列表")
    @PostMapping("/list")
    public Result<PageResponse<GroupDistributionListDTO>> list(@RequestBody @Valid GroupDistributionListReq req) {
        return Result.success(groupDistributionService.list(req));
    }

    @ApiOperation(value = "新增团队分配表（派团）", notes = "新增团队分配表（派团）")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.ADD, operTitle = "新增团队分配表（派团）", operDesc = "新增团队分配表（派团）")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid GroupDistributionAddReq req) {
        return groupDistributionService.add(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查看团队分配表（派团）", notes = "查看团队分配表（派团）")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.QUERY, operTitle = "查看团队分配表（派团）", operDesc = "查看团队分配表（派团）")
    @PostMapping("/query")
    public Result<GroupDistributionListDTO> query(@RequestBody @Valid GroupDistributionIdReq req) {
        return Result.success(groupDistributionService.query(req));
    }

    @ApiOperation(value = "查询派团信息详情", notes = "查询派团信息详情")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{id}")
    public Result<GroupInfoDTO> queryById(@PathVariable("id") Long id) {
        return groupDistributionService.queryById(id);
    }

    @ApiOperation(value = "修改团队分配表（派团）", notes = "修改团队分配表（派团）")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.UPDATE, operTitle = "修改团队分配表（派团）", operDesc = "修改团队分配表（派团）")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid GroupDistributionUpdateReq req) {
        return groupDistributionService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改团队分配时间（派团）", notes = "修改团队分配时间（派团）")
    @OperationLogAnnotation(operModul = OperationLogModel.GUIDE, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestBody @Valid GroupDistributionIdUpdateStatusReq req) {
        return groupDistributionService.updateTime(req, getCurrentUser(getRequest()).getId());
    }

}
